﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using FileSystem.Models;

namespace FileSystem.Services.IServices {
    /// <summary>
    /// 目录项存储接口
    /// </summary>
    public interface IDirItemStorage {
        /// <summary>
        /// 初始化目录项存储
        /// </summary>
        Task InitializeAsync();

        /// <summary>
        /// 目录项存储是否已经初始化
        /// </summary>
        bool IsInitialized();

        /// <summary>
        /// 增加目录项
        /// </summary>
        /// <param name="dirItem">要添加的目录项</param>
        Task AddAsync(DirItem dirItem);

        /// <summary>
        /// 删除目录项
        /// </summary>
        /// <param name="dirItem">要删除的目录项</param>
        Task RemoveAsync(DirItem dirItem);

        /// <summary>
        /// 修改目录项的属性
        /// </summary>
        /// <param name="dirItem">目录项</param>
        /// <param name="property">要修改的属性</param>
        /// <param name="newContent">新的值</param>
        Task ModifyProperty(DirItem dirItem, DirItemConst.Property property,
            string newContent);

        /// <summary>
        /// 修改目录项的属性
        /// </summary>
        /// <param name="dirItem">目录项</param>
        /// <param name="property">要修改的属性</param>
        /// <param name="newContent">新的值</param>
        Task ModifyProperty(DirItem dirItem, DirItemConst.Property property,
            bool newContent);

        /// <summary>
        /// 修改目录项的属性
        /// </summary>
        /// <param name="dirItem">目录项</param>
        /// <param name="property">要修改的属性</param>
        /// <param name="newContent">新的值</param>
        Task ModifyProperty(DirItem dirItem, DirItemConst.Property property,
            int newContent);

        Task<DirItem> GetDirItemAsync(int id);

        /// <summary>
        /// 根据目录项名获得一个目录项
        /// </summary>
        /// <param name="location">路径</param>
        /// <param name="dirItemName">目录项名</param>
        Task<DirItem> GetDirItemAsync(string location,string dirItemName);

        /// <summary>   
        /// 获得某个路径下的所有目录项
        /// </summary>
        /// <param name="location">路径</param>
        Task<IList<DirItem>> GetDirItemsAsync(string location);

        /// <summary>
        /// 判断目录项是否存在
        /// </summary>
        /// <param name="location">路径</param>
        /// <param name="dirItemName">目录项名</param>
        Task<bool> Exist(string location,string dirItemName);
    }

    /// <summary>
    /// 目录项存储常量
    /// </summary>
    public static class DirItemStorageConstants
    {
        /// <summary>
        /// 默认的目录项数据库版本号。
        /// </summary>
        public const int DefaultVersion = 0;

        /// <summary>
        /// 目录项数据库版本号。
        /// </summary>
        public const int Version = 1;

        /// <summary>
        /// 目录项数据库版本号键。
        /// </summary>
        public const string VersionKey = nameof(DirItemStorageConstants) +
            "." + nameof(Version);
    }
}